package com.ztk.threadbasic.callable;

import java.util.Objects;
import java.util.concurrent.*;

public class Callable01 implements Callable {
    @Override
    public Object call() throws Exception {
        try{
            System.out.println("callable");
            Thread.sleep(1000 * 10);
            return "good";
        } catch (Exception e) {
            System.out.println(e.getMessage());
            System.out.println(e);
            throw new Exception("发生异常啦");
        }
    }

    public static void main(String[] args) {
        Callable01 callable01 = new Callable01();
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        Future submit = executorService.submit(callable01);
        // executorService.execute();

        executorService.shutdown();

        try {
            Object obj = submit.get();
            if (!Objects.isNull(obj)) {
                System.out.println(obj);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
